package com.dinzeer.slashblade_useful_addon.mixin;

import com.aetherteam.aether.AetherTags;
import com.aetherteam.aether.block.AetherBlocks;
import com.aetherteam.aether.entity.monster.dungeon.boss.Slider;
import mods.flammpfeil.slashblade.entity.EntityAbstractSummonedSword;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import net.minecraft.world.Difficulty;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.ToolActions;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Optional;

@Mixin(Slider.class)
public class SliderMixin {

    @Inject(
            method = "canDamageSlider",
            at = @At("HEAD"),
            cancellable = true,
            remap = false
    )
    private void allowSlashBladeDamage(DamageSource source, CallbackInfoReturnable<Optional<LivingEntity>> cir) {
        Entity directEntity = source.getDirectEntity();
        if (directEntity instanceof LivingEntity) {
            LivingEntity attacker = (LivingEntity) directEntity;
            ItemStack mainHandItem = attacker.getMainHandItem();


            if (mainHandItem.getItem() instanceof ItemSlashBlade) {
                // 允许伤害并返回攻击者
                cir.setReturnValue(Optional.of(attacker));
                cir.cancel();
            }
        }
    }
}
